package exam;


import java.nio.file.FileSystemNotFoundException;
import java.sql.Array;
import java.sql.Statement;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        int[][] arr = {
                {1,2},
                {2,3},
                {3,4},
                {4,5},
                {6,5},
                {7,8}
        };
        System.out.println(getRes(arr));
    }

    public static boolean getRes(int[][] arr){
        HashSet<Integer> set = new HashSet<>();
        for (int[] a:arr){
            if (!set.contains(a[0])){
                set.add(a[0]);
                set.add(a[1]);
            }else if (set.contains(a[0])){
                if (set.contains(a[1])){
                    return true;
                }else{
                    set.add(a[1]);
                }
            }
        }
        return false;
    }
    public static int buy(int money, int[] items){
       sort(items);
        return buy1(money,items,0);
    }


    //买当前位置的可以获得的总次数  不买当前位置 获得的总次数
    public static int buy1(int money,int[] items,int index){
        if (money==0){
            return 1;
        }
        if (index==items.length-1 && money>0){
            if (money%items[index]==0){
                return 1;
            }
            return 0;
        }

        int rest = money;
        int res = 0;
        for (int a=0;a*items[index] <=money;a++){
            if (rest>=a*items[index]){
                res += buy1(rest-a*items[index],items,index+1);
                rest -=a*items[index];
            }
        }
        if (rest>0){
            res+=buy1(rest,items,index+1);
        }
        return res;
    }
    public static void sort(int[] nums){
        if (nums.length<2){
            return;
        }
        for (int i=0;i<nums.length;i++){
            for (int j=0;j<nums.length-i-1;j++){
                if (nums[j] < nums[j+1]){
                    int temp=nums[j];
                    nums[j] = nums[j+1];
                    nums[j+1] = temp;
                }
            }
        }
    }


    public static int getCC(int n){
        if(n==0){
            return 0;
        }
        int[] cc = {2,3,5};
        ArrayList<Integer> arr = new ArrayList<>();
        arr.add(1);
        arr.add(2);
        arr.add(3);
        arr.add(5);
        for (int a=1;a<=n;a++){
            for (int b=0;b<3;b++){
                int temp = arr.get(a)*cc[b];
                if (!arr.contains(temp)){
                    arr.add(temp);
                    Collections.sort(arr);
                }
            }
        }

        return arr.get(n-1);
    }
    public static int getC(int n){
        if (n==0){
            return 0;
        }
        int count = 0;
        int a=0;
        while (count<n){
            a++;
            if (isC(a)){
                count++;
            }
        }
        return a;
    }

    //判断是不是丑数
    public static boolean isC(int num){
        while (num!=1){
            if (num%2==0){
                num/=2;
            }else if (num%3==0){
                num/=3;
            }else if (num%5==0){
                num/=5;
            }else {
                break;
            }
        }
        return num==1;
    }

    public static List<Integer> generate(int numRows) {
        List<Integer> list = null;
        List<Integer> lastList = list;
        for(int a=0;a<=numRows;a++){
            list = new ArrayList<>();
            if(a==0){
                list.add(1);
                lastList = list;
                continue;
            }
            for(int b=0;b<=a;b++){
                if(b==0){
                    list.add(lastList.get(0));
                }else if(b==a){
                    list.add(lastList.get(a-1));
                }else{
                    list.add(lastList.get(b-1)+lastList.get(b));
                }
            }
            lastList = list;
        }
        return list;
    }
}
